package ooday04;

public class PolymorphicDemo {
    public static void main(String[] args) {
        /*
        Dog o1 = new Dog("小黑",2,"黑");
        //o1.name,o1.age,o1.color,o1.lookHome(),o1.swim(),o1.eat();,o1.drink();
        Animal o2 = new Dog("小黑",2,"黑");
        //o2.name,o2.age,o2.color,o2.eat();,o2.drink()
        Swim o3 = new Dog("小黑",2,"黑");
        //o3.swim()

         */
        /*
        Master master = new Master();
         Dog dog = new Dog("小黑",2,"黑");
        Chick chick = new Chick("小黄",1,"黄");
        Fish fish = new Fish("小花",1,"花");
        master.feed(dog);
        master.feed(chick);
        master.feed(fish);

         */

        Animal[] animals = new Animal[]{new Dog("小黑",2,"黑"),new Chick("小黄",1,"黄"),new Fish("小花",1,"花")};
        for (int i = 0; i < animals.length; i++) {
            animals[i].eat();
            System.out.println( animals[i].name);
            animals[i].drink();

            if (animals[i] instanceof Dog){
                Dog d = (Dog)animals[i];
                d.lookHome();
            }
            if (animals[i] instanceof Swim){
                Swim s = (Swim)animals[i];
                s.swim();
            }
            if (animals[i] instanceof Chick){
                Chick c = (Chick)animals[i];
                c.layEggs();
            }



        }
        //演示强转成功的条件
        /*
        Animal o = new Dog("小黑",2,"黑");
        Dog g = (Dog)o;
        Swim s = (Swim)o;
        System.out.println(o instanceof Dog);
        System.out.println(o instanceof Swim);
        System.out.println(o instanceof Fish);
        if (o instanceof Fish){
            Fish f = (Fish)o;
        }

         */
    }
}
